Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a random Drip List ID when creating a new Drip List #1406

Conversation

mhgbrown
Copy link
Collaborator

@mhgbrown mhgbrown commented Dec 21, 2024

Removes the count of Drip Lists when determining a salt for a new Drip List.

@mhgbrown mhgbrown linked an issue Dec 21, 2024 that may be closed by this pull request
Copy link

railway-app bot commented Dec 21, 2024

🚅 Previously deployed to Railway in the Drips App project. Environment has been deleted.

@mhgbrown mhgbrown force-pushed the mhgbrown-991-generate-a-random-drip-list-id-when-creating-a-new-drip-list branch from 5f5c3f2 to 0f3ed61 Compare December 31, 2024 00:46
@mhgbrown mhgbrown marked this pull request as ready for review December 31, 2024 00:59
// We use the count of *all* NFT sub-accounts to generate the salt for the Drip List ID.
// This is because we want to avoid making HTTP requests to the subgraph for each NFT sub-account to check if it's a Drip List.
private _calcSaltFromAddress = (address: string, listCount: number): bigint /* 64bit */ => {
// Create random salt from address
Copy link
Collaborator

@jtourkos jtourkos Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this generates a random number?
I think for the same address it will produce the same output, no?

(Even the previous code, I believe wasn't truly random.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not sure and it looks like it doesn't based on the error I'm receiving. Will look into it!

* move calculateSaltFromAddress to util function
);
const addressBigInt = ethers.toBigInt('0x' + hash.slice(26));

const randomBytes = ethers.randomBytes(32);
Copy link
Collaborator

@jtourkos jtourkos Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely introduces randomness now 👍
But, why not simplifying to something simple like:

export default function generateRandomNumber() {
  const randomBytes = ethers.randomBytes(32);
  return BigInt(ethers.hexlify(randomBytes)) & BigInt('0xFFFFFFFFFFFFFFFF');
}

This is purely random compared to what we had before where the final result is partially influenced by the (deterministic) seed and address.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason at all. Just not trying to shake the tree too much because I don't know what constraints the seed should have. Will update!

@@ -108,7 +108,7 @@ export default class DripListService {
items,
);

const salt = this._calcSaltFromAddress(this._ownerAddress);
const salt = this._calcSaltFromAddress();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor suggestion (otherwise feel free to close it 👍): Why not directly calling calculateRandomSalt instead of wrapping it in a "private" _calcSaltFromAddress.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No real important reason - just trying to keep the integrity of the class's internal API. I'll just use the utility directly

@mhgbrown mhgbrown merged commit 14dbe49 into main Jan 9, 2025
5 checks passed
@mhgbrown mhgbrown deleted the mhgbrown-991-generate-a-random-drip-list-id-when-creating-a-new-drip-list branch January 9, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate a random Drip List ID when creating a new Drip List
2 participants